package com.xuexiang.xuidemo.slice;

import com.xuexiang.xui_lib.component.dialog.config.ChooseBean;
import com.xuexiang.xui_lib.component.dialog.config.ConfigBean;
import com.xuexiang.xui_lib.component.dialog.interfaces.CheckBoxItemDialogListener;
import com.xuexiang.xui_lib.component.dialog.interfaces.DialogListener;
import com.xuexiang.xui_lib.component.dialog.interfaces.ItemDialogListener;
import com.xuexiang.xui_lib.component.dialog.view.StyledDialog;
import com.xuexiang.xui_lib.component.spinner.MaterialSpinner;
import com.xuexiang.xuidemo.ResourceTable;
import com.xuexiang.xuidemo.util.ToastUtil;
import com.xuexiang.xuidemo.view.BallClipRotateIndicator;
import com.xuexiang.xuidemo.view.DialogDropdownText;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.*;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.components.element.StateElement;
import ohos.agp.utils.Color;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.utils.TextAlignment;
import ohos.agp.window.dialog.*;
import ohos.app.Context;
import ohos.eventhandler.EventHandler;
import ohos.eventhandler.EventRunner;
import ohos.eventhandler.InnerEvent;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * MaterialDialog对话框
 *
 * @since 2021-04-08
 */
public class MaterialAbilitySlice extends AbilitySlice implements Component.ClickedListener, BaseDialog.DialogListener {
    private Image image_back;
    ConfigBean configBean = null;
    private DirectionalLayout dl_one, dl_two, dl_three, dl_four, dl_five, dl_six, dl_seven, dl_eight, dl_nine, dl_ten;
    private DirectionalLayout dl_edit, dl_add, dl_delete, dl_update;
    CommonDialog commonDialog;
    private Text tv_progress, tv_count, tv_dialog_message, tv_alert_dialog_cancel, tv_alert_dialog_ok, input_dialog_text, alert_custom_sort;
    private ProgressBar progressBar, progressBarOne;
    int maxProgress = 0;
    int currentProgress = 0;
    int currentProgressOne = 0;
    DirectionalLayout vLoading;
    ShapeElement mCommonElement;
    StringBuffer stringBuffer = new StringBuffer();
    String strLine;
    List<String> components = new ArrayList<>();
    //获取当前主线程的EventRunner，用来存放事件队列
    private EventHandler handler = new EventHandler(EventRunner.current()) {
        protected void processEvent(InnerEvent event) {
            super.processEvent(event);
            if (event == null) {
                return;
            }
            if (event.eventId == 110) {
                int paramValue = (int) event.param;
                tv_progress.setText(paramValue + "%");
                progressBar.setProgressValue(paramValue);
                tv_count.setText(Math.round(paramValue * 1.5) + "/150");
                if (paramValue == 100) {
                    tv_dialog_message.setText("下载完毕！");
                }
            }
        }
    };
    private EventHandler handlerOne = new EventHandler(EventRunner.current()) {
        protected void processEvent(InnerEvent event) {
            super.processEvent(event);
            if (event == null) {
                return;
            }
            if (event.eventId == 120) {
                int paramValue = (int) event.param;
                progressBarOne.setProgressValue(paramValue);
            }
        }
    };
    private Switch btn_switch;
    private int mPositon;
    List<String> mSelectList = new ArrayList<>();
    private static final String[] OHOS_VERSIONS = {
        "根据品牌名称排序",
        "根据价格升序排序",
        "根据价格降序排序",
        "根据销售量升序排序",
        "根据销售量降序排序",
        "综合排序"
    };
    Component tv_component;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_material);
        initView();
        initData();
        initClickedListener();
    }

    public void initView() {
        image_back = (Image) findComponentById(ResourceTable.Id_image_back);
        dl_one = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_one);
        dl_two = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_two);
        dl_three = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_three);
        dl_four = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_four);
        dl_five = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_five);
        dl_six = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_six);
        dl_seven = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_seven);
        dl_eight = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_eight);
        dl_nine = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_nine);
        dl_ten = (DirectionalLayout) findComponentById(ResourceTable.Id_dl_ten);
        tv_component = (Component) findComponentById(ResourceTable.Id_component);
        tv_component.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (commonDialog != null) {
                    commonDialog.hide();
                    tv_component.setVisibility(Component.HIDE);
                }
            }
        });
    }

    private void initClickedListener() {
        image_back.setClickedListener(this);
        dl_one.setClickedListener(this);
        dl_two.setClickedListener(this);
        dl_three.setClickedListener(this);
        dl_four.setClickedListener(this);
        dl_five.setClickedListener(this);
        dl_six.setClickedListener(this);
        dl_seven.setClickedListener(this);
        dl_eight.setClickedListener(this);
        dl_nine.setClickedListener(this);
        dl_ten.setClickedListener(this);
    }

    private void initData() {
        mSelectList.add("路线一: 南京->上海->杭州");
        mSelectList.add("路线二: 南京->武汉->长沙");
        mSelectList.add("路线三: 南京->济南->天津");
        mSelectList.add("路线四: 南京->合肥->重庆");
        mSelectList.add("路线五: 南京->徐州->北京");
        mSelectList.add("路线六: 南京->郑州->成都");
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_image_back:
                onBackPressed();
                break;
            case ResourceTable.Id_dl_one:
                configBean = StyledDialog.buildTipImageAlert(getContext(), "提示", "请注意，这是一个简单的提示性对话框！", "确定", "", new DialogListener() {
                    @Override
                    public void positiveButton() {
                        configBean.commonDialog.hide();
                        configBean.commonDialog = null;
                    }

                    @Override
                    public void negativeButton() {
                        configBean.commonDialog.hide();
                        configBean.commonDialog = null;
                    }
                });
                configBean.commonDialog.show();
                break;
            case ResourceTable.Id_dl_two:
                configBean = StyledDialog.buildTipAlert(getContext(), "", "是否允许打开蓝牙？", "是", "否", new DialogListener() {
                    @Override
                    public void positiveButton() {
                        configBean.commonDialog.hide();
                        configBean.commonDialog = null;
                    }

                    @Override
                    public void negativeButton() {
                        configBean.commonDialog.hide();
                        configBean.commonDialog = null;
                    }
                });
                configBean.commonDialog.show();
                break;
            case ResourceTable.Id_dl_three:
                configBean = StyledDialog.buildCountInput(getContext(), "警告", "请输入密码", new DialogListener() {

                    @Override
                    public void positiveButton() {
                        //可对输入内容进行校验
                        configBean.getInputText1();
                        configBean.commonDialog.hide();
                    }

                    @Override
                    public void negativeButton() {
                        configBean.commonDialog.hide();
                    }
                });
                configBean.commonDialog.show();
                break;
            case ResourceTable.Id_dl_four:
                CharSequence[] words1 = {"添加", "修改", "更新", "删除"};
                boolean[] selectItems1 = {true, false, false, false};

                ArrayList<ChooseBean> list1 = new ArrayList<>();
                for (int i = 0; i < words1.length; i++) {
                    ChooseBean chooseBean = new ChooseBean();
                    chooseBean.setTxt(words1[i]);
                    chooseBean.setChoosen(selectItems1[i]);
                    list1.add(chooseBean);
                }
                configBean = StyledDialog.buildMdIOSListOther(getContext(), list1, new ItemDialogListener() {
                    @Override
                    public void onItemClick(CharSequence text, int position) {
                        if (position == 0) {
                            ToastUtil.showToast(getContext(), "0:添加");
                        } else {
                            ToastUtil.showToast(getContext(), position + ":" + list1.get(position).getTxt().toString());
                        }
                        configBean.commonDialog.hide();
                    }

                    @Override
                    public void positiveButton() {
                        configBean.commonDialog.hide();
                        configBean.commonDialog = null;

                    }

                    @Override
                    public void negativeButton() {
                        configBean.commonDialog.hide();
                        configBean.commonDialog = null;
                    }
                });
                configBean.commonDialog.show();
                break;
            case ResourceTable.Id_dl_five:
                CharSequence[] words = {"路线一: 南京->上海->杭州", "路线二: 南京->武汉->长沙", "路线三: 南京->济南->天津", "路线四: 南京->合肥->重庆", "路线五: 南京->徐州->北京", "路线六: 南京->郑州->成都"};
                boolean[] selectItems = {true, false, false, false, false, false};

                ArrayList<ChooseBean> list2 = new ArrayList<>();
                for (int i = 0; i < words.length; i++) {
                    ChooseBean chooseBean = new ChooseBean();
                    chooseBean.setTxt(words[i]);
                    chooseBean.setChoosen(selectItems[i]);
                    list2.add(chooseBean);
                }
                configBean = StyledDialog.buildMySingleChoose(getContext(), "路线设置", "选择", "取消", list2, new ItemDialogListener() {
                    @Override
                    public void onItemClick(CharSequence text, int position) {
                        mPositon = position;
                        strLine = String.valueOf(list2.get(position).getTxt());
                    }

                    @Override
                    public void positiveButton() {
                        if (mPositon == 0) {
                            ToastUtil.showToast(getContext(), "0:路线一: 南京->上海->杭州");
                        } else {
                            ToastUtil.showToast(getContext(), mPositon + ":" + strLine);
                        }
                        configBean.commonDialog.hide();
                        configBean.commonDialog = null;

                    }

                    @Override
                    public void negativeButton() {
                        configBean.commonDialog.hide();
                        configBean.commonDialog = null;
                    }
                });
                configBean.commonDialog.show();
                break;
            case ResourceTable.Id_dl_six:
                components.add("0");
                components.add("1");
                CharSequence[] wordArray = {"路线一: 南京->上海->杭州", "路线二: 南京->武汉->长沙", "路线三: 南京->济南->天津", "路线四: 南京->合肥->重庆", "路线五: 南京->徐州->北京", "路线六: 南京->郑州->成都"};
                boolean[] checkedItems = {true, true, false, false, false, false};
                ArrayList<ChooseBean> list = new ArrayList<>();
                for (int i = 0; i < wordArray.length; i++) {
                    ChooseBean chooseBean = new ChooseBean();
                    chooseBean.setTxt(wordArray[i]);
                    chooseBean.setChoosen(checkedItems[i]);
                    list.add(chooseBean);
                }
                configBean = StyledDialog.buildMdMultiChoose(getContext(), "路线设置", list,
                    new CheckBoxItemDialogListener() {
                        @Override
                        public void onItemClick(Checkbox checkbox, int position) {
                            checkedItems[position] = checkbox.isChecked();
                            mPositon = position;
                            if (checkbox.isChecked()) {
                                components.add(position + "");
                            } else {
                                components.remove(position + "");
                            }
                        }

                        @Override
                        public void positiveButton() {
                            configBean.commonDialog.hide();
                            configBean.commonDialog = null;

                            for (int i = 0; i < components.size(); i++) {
                                stringBuffer.append(mSelectList.get(Integer.parseInt(components.get(i))) + "\n");

                            }
                            showCustomText(getContext(), "选中：" + "\n" + stringBuffer.toString());
                            components.clear();
                            stringBuffer.delete(0, stringBuffer.length());
                        }

                        @Override
                        public void negativeButton() {
                            configBean.commonDialog.hide();
                            configBean.commonDialog = null;
                        }
                    });
                configBean.commonDialog.show();
                break;
            case ResourceTable.Id_dl_seven:
                commonDialog = new CommonDialog(this);
                Component mLayout = LayoutScatter.getInstance(this).parse(ResourceTable.Layout_alert_update_version_dialog_layout, null, true);
                commonDialog.setTransparent(true);
                commonDialog.setContentCustomComponent(mLayout);
                progressBar = (ProgressBar) mLayout.findComponentById(ResourceTable.Id_progressBar);
                tv_dialog_message = (Text) mLayout.findComponentById(ResourceTable.Id_alert_update_dialog_message);
                tv_progress = (Text) mLayout.findComponentById(ResourceTable.Id_tv_progress);
                maxProgress = progressBar.getMax();
                tv_count = (Text) mLayout.findComponentById(ResourceTable.Id_tv_count);
                tv_alert_dialog_cancel = (Text) mLayout.findComponentById(ResourceTable.Id_alert_dialog_cancel);
                tv_alert_dialog_cancel.setClickedListener(new Component.ClickedListener() {
                    @Override
                    public void onClick(Component component) {
                        commonDialog.hide();
                        currentProgress = 0;
                    }
                });
                commonDialog.show();
                begin();
                break;
            case ResourceTable.Id_dl_eight:
                commonDialog = new CommonDialog(this);
                Component mLayoutTwo = LayoutScatter.getInstance(this).parse(ResourceTable.Layout_alert_image_load_dialog_layout, null, true);
                DirectionalLayout dl_load_dialog = (DirectionalLayout) mLayoutTwo.findComponentById(ResourceTable.Id_dl_load_dialog);
                commonDialog.setSize(ComponentContainer.LayoutConfig.MATCH_PARENT, 600);
                commonDialog.setAlignment(LayoutAlignment.CENTER);
                commonDialog.setTransparent(true);
                commonDialog.setContentCustomComponent(mLayoutTwo);
                vLoading = (DirectionalLayout) mLayoutTwo.findComponentById(ResourceTable.Id_loading);
                mCommonElement = new ShapeElement();
                mCommonElement.setRgbColor(new RgbColor(0, 0, 0));
                mCommonElement.setAlpha(0);
                DirectionalLayout.LayoutConfig mBallClipRotateIndicatorConfig = new DirectionalLayout.LayoutConfig(DirectionalLayout.LayoutConfig.MATCH_CONTENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT);
                mBallClipRotateIndicatorConfig.setMargins(100, 0, 40, 0);
                BallClipRotateIndicator ballClipRotateIndicator = new BallClipRotateIndicator(getContext());
                ballClipRotateIndicator.setLayoutConfig(mBallClipRotateIndicatorConfig);
                ballClipRotateIndicator.setHeight(200);
                ballClipRotateIndicator.setWidth(200);
                ballClipRotateIndicator.setBackground(mCommonElement);
                vLoading.addComponent(ballClipRotateIndicator);
                DirectionalLayout.LayoutConfig mTextConfig = new DirectionalLayout.LayoutConfig(DirectionalLayout.LayoutConfig.MATCH_PARENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT);
                mTextConfig.setMargins(10, 0, 10, 0);
                Text mText = new Text(getContext());
                mText.setLayoutConfig(mTextConfig);
                mText.setHeight(100);
                mText.setTextSize(40);
                mText.setTextColor(Color.BLACK);
                mText.setText("数据接收中，请稍后...");
                vLoading.addComponent(mText);
                if (ballClipRotateIndicator != null) {
                    ballClipRotateIndicator.start();
                }
                tv_alert_dialog_cancel = (Text) mLayoutTwo.findComponentById(ResourceTable.Id_alert_dialog_cancel);
                tv_alert_dialog_cancel.setClickedListener(new Component.ClickedListener() {
                    @Override
                    public void onClick(Component component) {
                        commonDialog.hide();
                    }
                });
                dl_load_dialog.setClickedListener(new Component.ClickedListener() {
                    @Override
                    public void onClick(Component component) {
                        if (commonDialog != null) {
                            commonDialog.destroy();
                        }
                    }
                });
                commonDialog.show();
                break;
            case ResourceTable.Id_dl_nine:
                CommonDialog mCommonDialog = new CommonDialog(this);
                Component layout = LayoutScatter.getInstance(this).parse(ResourceTable.Layout_list_single_image_entry_layout, null, true);
                mCommonDialog.setTransparent(true);
                mCommonDialog.setSize(ComponentContainer.LayoutConfig.MATCH_PARENT, 600);
                mCommonDialog.setAlignment(LayoutAlignment.CENTER);
                mCommonDialog.setContentCustomComponent(layout);
                dl_edit = (DirectionalLayout) layout.findComponentById(ResourceTable.Id_dl_edit);
                DependentLayout dp_edit = (DependentLayout) layout.findComponentById(ResourceTable.Id_dp_edit);
                dl_edit.setClickedListener(new Component.ClickedListener() {
                    @Override
                    public void onClick(Component component) {
                        ToastUtil.showToast(getContext(), "编辑");
                        mCommonDialog.hide();
                    }
                });
                dl_add = (DirectionalLayout) layout.findComponentById(ResourceTable.Id_dl_add);
                dl_add.setClickedListener(new Component.ClickedListener() {
                    @Override
                    public void onClick(Component component) {
                        ToastUtil.showToast(getContext(), "添加");
                        mCommonDialog.hide();
                    }
                });
                dl_delete = (DirectionalLayout) layout.findComponentById(ResourceTable.Id_dl_delete);
                dl_delete.setClickedListener(new Component.ClickedListener() {
                    @Override
                    public void onClick(Component component) {
                        ToastUtil.showToast(getContext(), "删除");
                        mCommonDialog.hide();
                    }
                });
                dl_update = (DirectionalLayout) layout.findComponentById(ResourceTable.Id_dl_update);
                dl_update.setClickedListener(new Component.ClickedListener() {
                    @Override
                    public void onClick(Component component) {
                        ToastUtil.showToast(getContext(), "更新");
                        mCommonDialog.hide();
                    }
                });
                dp_edit.setClickedListener(new Component.ClickedListener() {
                    @Override
                    public void onClick(Component component) {
                        if (mCommonDialog != null)
                            mCommonDialog.destroy();
                    }
                });
                mCommonDialog.show();
                break;
            case ResourceTable.Id_dl_ten:
                PopupDialog commonDialog = new PopupDialog(this, null);
                commonDialog.setSize(900, 1050);
                commonDialog.setAlignment(LayoutAlignment.CENTER);
                commonDialog.setAutoClosable(true);
                commonDialog.setDialogListener(this);
                Component mLayoutThree = LayoutScatter.getInstance(this).parse(ResourceTable.Layout_alert_dialog_layout_spinner_vertical, null, true);
                commonDialog.setCustomComponent(mLayoutThree);
                progressBarOne = (ProgressBar) mLayoutThree.findComponentById(ResourceTable.Id_progressBar);
                MaterialSpinner spinner = (MaterialSpinner) mLayoutThree.findComponentById(ResourceTable.Id_spinner);
                spinner.setItems(OHOS_VERSIONS);
                spinner.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener<String>() {
                    @Override
                    public void onItemSelected(MaterialSpinner view, int position, long id, String item) {
                    }
                });
                DependentLayout dl_select = (DependentLayout) mLayoutThree.findComponentById(ResourceTable.Id_dl_select);
                DialogDropdownText selectSpinner = (DialogDropdownText) mLayoutThree.findComponentById(ResourceTable.Id_viewdrop6_1);
                selectSpinner.settextfile();
                dl_select.setClickedListener(new Component.ClickedListener() {
                    @Override
                    public void onClick(Component component) {
                        ShapeElement element = new ShapeElement();
                        element.setCornerRadius(20);
                        element.setStroke(5, new RgbColor(43, 158, 227));
                        dl_select.setBackground(element);
                    }
                });
                initSwitch(mLayoutThree);
                input_dialog_text = (Text) mLayoutThree.findComponentById(ResourceTable.Id_input_dialog_text_field);
                tv_alert_dialog_cancel = (Text) mLayoutThree.findComponentById(ResourceTable.Id_spinner_dialog_cancle);
                tv_alert_dialog_ok = (Button) mLayoutThree.findComponentById(ResourceTable.Id_spinner_dialog_ok);
                tv_alert_dialog_cancel.setClickedListener(new Component.ClickedListener() {
                    @Override
                    public void onClick(Component component) {
                        commonDialog.hide();
                        tv_component.setVisibility(Component.HIDE);
                    }
                });
                tv_alert_dialog_ok.setClickedListener(new Component.ClickedListener() {
                    @Override
                    public void onClick(Component component) {
                        commonDialog.hide();
                        tv_component.setVisibility(Component.HIDE);
                    }
                });
                tv_component.setVisibility(Component.VISIBLE);
                commonDialog.show();
                startProgress();
                break;
            default:

                break;
        }
    }

    private void initSwitch(Component layout) {
        ShapeElement elementThumbOn = new ShapeElement();
        elementThumbOn.setShape(ShapeElement.OVAL);
        elementThumbOn.setRgbColor(RgbColor.fromArgbInt(0xFF1E90FF));
        elementThumbOn.setCornerRadius(50);
        // 关闭状态下滑块的样式
        ShapeElement elementThumbOff = new ShapeElement();
        elementThumbOff.setShape(ShapeElement.OVAL);
        elementThumbOff.setRgbColor(RgbColor.fromArgbInt(0xFFFFFFFF));
        elementThumbOff.setCornerRadius(50);
        // 开启状态下轨迹样式
        ShapeElement elementTrackOn = new ShapeElement();
        elementTrackOn.setShape(ShapeElement.RECTANGLE);
        elementTrackOn.setRgbColor(RgbColor.fromArgbInt(0xFF87CEFA));
        elementTrackOn.setCornerRadius(50);
        // 关闭状态下轨迹样式
        ShapeElement elementTrackOff = new ShapeElement();
        elementTrackOff.setShape(ShapeElement.RECTANGLE);
        elementTrackOff.setRgbColor(RgbColor.fromArgbInt(0xFF808080));
        elementTrackOff.setCornerRadius(50);
        btn_switch = (Switch) layout.findComponentById(ResourceTable.Id_btn_switch);
        btn_switch.setTrackElement(trackElementInit(elementTrackOn, elementTrackOff));
        btn_switch.setThumbElement(thumbElementInit(elementThumbOn, elementThumbOff));
    }

    private StateElement trackElementInit(ShapeElement on, ShapeElement off) {
        StateElement trackElement = new StateElement();
        trackElement.addState(new int[]{ComponentState.COMPONENT_STATE_CHECKED}, on);
        trackElement.addState(new int[]{ComponentState.COMPONENT_STATE_EMPTY}, off);
        return trackElement;
    }

    private StateElement thumbElementInit(ShapeElement on, ShapeElement off) {
        StateElement thumbElement = new StateElement();
        thumbElement.addState(new int[]{ComponentState.COMPONENT_STATE_CHECKED}, on);
        thumbElement.addState(new int[]{ComponentState.COMPONENT_STATE_EMPTY}, off);
        return thumbElement;
    }

    public void begin() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (currentProgress < maxProgress) {
                    currentProgress += 1;
                    handler.sendEvent(InnerEvent.get(110, currentProgress));
                    try {
                        Thread.sleep(200);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();
    }

    public void startProgress() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (currentProgressOne < 101) {
                    Random random = new Random();
                    int currentProgressOne = random.nextInt(100);
                    handlerOne.sendEvent(InnerEvent.get(120, currentProgressOne));
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();
    }

    public static void showCustomText(Context context, String toastStr) {
        Text textComponent = new Text(context);
        textComponent.setText(toastStr);
        int padding = AttrHelper.fp2px(20, context);
        //设置间距为10vp
        //int left, int top, int right, int bottom
        textComponent.setPadding(padding, 5, 10, 5);
        textComponent.setMarginLeft(10);
        textComponent.setTextColor(Color.WHITE);
        textComponent.setTextAlignment(TextAlignment.CENTER);
        textComponent.setTextSize(AttrHelper.fp2px(12, context));
        ShapeElement shapeElement = new ShapeElement();
        //  shapeElement.setShape(ShapeElement.RECTANGLE);
        //设置背景半透明
        shapeElement.setRgbColor(RgbColor.fromArgbInt(Color.rgb(108, 118, 124)));
        shapeElement.setCornerRadius(AttrHelper.fp2px(30, context));
        textComponent.setBackground(shapeElement);
        //设置文字允许多行
        textComponent.setMultipleLine(true);

        DirectionalLayout.LayoutConfig layoutConfig = new DirectionalLayout.LayoutConfig();
        layoutConfig.width = ComponentContainer.LayoutConfig.MATCH_CONTENT;
        layoutConfig.height = ComponentContainer.LayoutConfig.MATCH_CONTENT;
        layoutConfig.alignment = LayoutAlignment.CENTER;
        textComponent.setLayoutConfig(layoutConfig);

        ToastDialog toastDialog = new ToastDialog(context).setDuration(1000).setComponent(textComponent).setAlignment(LayoutAlignment.BOTTOM);
        //设置弹框背景透明
        toastDialog.setOffset(0, 50);
        toastDialog.setTransparent(true);
        toastDialog.show();
    }

    @Override
    public boolean isTouchOutside() {
        tv_component.setVisibility(Component.HIDE);
        return false;
    }
}

